package com.zk.shop.servlet.Msg;

import com.zk.shop.service.Impl.MsgServiceImpl;
import com.zk.shop.service.Impl.ReplyServiceImpl;
import com.zk.shop.service.MsgService;
import com.zk.shop.service.ReplyService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 根据留言ID删除当前留言
 */
@WebServlet("/DeleteMsgIdServlet")
public class DeleteMsgIdServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        MsgService msgService = new MsgServiceImpl();
        ReplyService replyService = new ReplyServiceImpl();
      int msgid =Integer.parseInt(request.getParameter("msgId")) ;
      //删除所属ID评论
      int flag  =   msgService.deleteMsg(msgid);
      //删除所属ID留言
       int f =  replyService.deleteReplyByMsgId(msgid);
        PrintWriter out=response.getWriter();
        if (flag!=0||f!=0){
            out.print(true);
            System.out.println("删除当前ID留言成功");
        }
        else {
            System.out.println("删除当前ID留言失败");
        }

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
